package com.universest.swordholder

import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import com.github.boybeak.skbglobal.SoftKeyboardGlobal

// 顶层函数：统一对外提供Application Context
fun getApplicationContext(): Context {
    if(SwordHolderApplication.previewContext!=null)return SwordHolderApplication.previewContext!!
    return SwordHolderApplication.instance
}

class SwordHolderApplication : Application() {

    companion object {
        // 使用lateinit延迟初始化，避免null处理；private set限制仅内部可赋值
        @SuppressLint("StaticFieldLeak")
        lateinit var instance: SwordHolderApplication
            private set

        @SuppressLint("StaticFieldLeak")
        var previewContext: Context? = null
    }

    override fun onCreate() {
        super.onCreate()
        // 在onCreate()中赋值：此时Application已完成所有初始化，状态稳定
        instance = this
        SoftKeyboardGlobal.install(this, false)
    }
}